package com.daohang361.imqq.encoder;

import com.daohang361.imqq.Asycore.QQUser;
import com.daohang361.imqq.protocol.QQ2011;
import com.daohang361.imqq.tool.ByteArray;
import com.daohang361.imqq.tool.MyByteSendArray;

public class EncoderCE extends AbstractEncoder {
	@Override
	public ByteArray doHead(QQUser myqq, String HexCommand) {
		ByteArray myByte = new MyByteSendArray();
		myByte.putInt(QQ2011.QQ_PROTOCOL_PACKAGE_HEAD);
		myByte.putInt(QQ2011.QQ_PROTOCOL_VERSION);
		myByte.putHex(HexCommand);
		myByte.putByte(myqq.getAttr("CEPakage"));//包增长应该在接受到此包后
		myByte.putInt(myqq.getQq());
		myByte.putByte(QQ2011.QQ_CONTEX_FIX_12);
		return myByte;
	}
	@Override
public byte[] encode(QQUser myqq, int command) {
		ByteArray myByte = doHead(myqq, "00CE");
		myByte.saveThis();//保存此段作为第0段
		myByte.putByte(myqq.getSend());
		myByte.saveThis();//保存此段作为第一段
		myByte.teaThis(1, 1,myqq.getAttr("SessionKey"));//加密第一段到第一段
		doTail(myByte);
		myqq.removeAttr("CEPakage");
		myqq.setCommand(0);//初始化回归
		return myByte.getByteList();//返回完整的package
	}
}
